FROM ubuntu:18.04
MAINTAINER Brick Yang <brick.yang@printfxxx.com>

ARG DEBIAN_FRONTEND=noninteractive
ARG APT_MIRROR_URL=archive.ubuntu.com
ARG PIP_MIRROR_URL=https://pypi.org/simple/

RUN cp /etc/apt/sources.list /etc/apt/sources.list.orig
RUN sed -i -e "s/archive.ubuntu.com/$APT_MIRROR_URL/g" /etc/apt/sources.list
RUN pip_mirror_host=${PIP_MIRROR_URL#*://} && echo "[global]\nindex-url = $PIP_MIRROR_URL\ntrusted-host = ${pip_mirror_host%%/*}" >> /etc/pip.conf

RUN rm -rf /var/lib/apt/lists/*
RUN apt-get autoclean && apt-get autoremove && apt-get update --fix-missing && apt-get upgrade --fix-missing -y \
	&& apt-get dist-upgrade --fix-missing -y && apt-get install -y apt-utils sudo locales
RUN echo 'dash dash/sh boolean false' | debconf-set-selections && dpkg-reconfigure dash
RUN echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen \
	&& echo 'locales locales/default_environment_locale select en_US.UTF-8' | debconf-set-selections \
	&& echo 'locales locales/locales_to_be_generated multiselect en_US.UTF-8' | debconf-set-selections \
	&& dpkg-reconfigure locales
RUN passwd -d root

RUN apt-get install -y openssh-server vim
RUN apt-get install -y autoconf automake dh-autoreconf libssl-dev zip openssl python-pip flex bison bc git gcc		\
	ethtool wget ftp make makedev tclsh binfmt-support qemu-system-common qemu-user-static debootstrap ncurses-dev	\
	gcc-arm-linux-gnueabihf crossbuild-essential-arm64 gcc-aarch64-linux-gnu file build-essential gdb u-boot-tools	\
	device-tree-compiler python python-dev curl libxml2-dev libsensors4-dev libedit-dev liblzma-dev tree libtool	\
	binutils-dev libnuma-dev libpcap-dev mtd-utils libncurses5-dev libelf-dev net-tools libcunit1-dev pkg-config	\
	autotools-dev openssh-client crossbuild-essential-armhf qemu-utils kmod g++-aarch64-linux-gnu python-crypto	\
	cpp-arm-linux-gnueabihf dosfstools ruby lsb-release g++-arm-linux-gnueabihf python-six python-pycryptodome
RUN echo 'UseDNS no' >> /etc/ssh/sshd_config

ADD startup.sh /usr/local/bin/startup.sh
RUN chmod a+x /usr/local/bin/startup.sh
ADD init.sh /usr/local/bin/init.sh
RUN chmod a+x /usr/local/bin/init.sh

ENTRYPOINT ["/usr/local/bin/startup.sh"]

EXPOSE 22
